/**
 * 
 */
package designpatterns.mvc.calculator;

import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * @author Cris
 * 
 */

public class CalculatorView extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6875392597489238551L;
	private JTextField firstNumber;
	private JLabel additionLabel;
	private JTextField secondNumber;
	private JButton calculateButton;
	private JTextField calcSolution;

	private void initComponents()
	{
		firstNumber = new JTextField(5);
		additionLabel = new JLabel("+");
		secondNumber = new JTextField(5);
		calculateButton = new JButton("Calculate");
		calcSolution = new JTextField(5);	
	}

	private void initLayout()
	{
		JPanel calcPanel = new JPanel();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(350, 80);

		calcPanel.add(firstNumber);
		calcPanel.add(additionLabel);
		calcPanel.add(secondNumber);
		calcPanel.add(calculateButton);
		calcPanel.add(calcSolution);

		this.add(calcPanel);		
	}
	
	CalculatorView() {

		// Sets up the view and adds the components
		initComponents();
		initLayout();

	}

	public int getFirstNumber() {

		return Integer.parseInt(firstNumber.getText());

	}

	public int getSecondNumber() {

		return Integer.parseInt(secondNumber.getText());

	}

	public int getCalcSolution() {

		return Integer.parseInt(calcSolution.getText());

	}

	public void setCalcSolution(int solution) {

		calcSolution.setText(Integer.toString(solution));

	}

	void addCalculateListener(ActionListener listenForCalcButton) {

		calculateButton.addActionListener(listenForCalcButton);

	}

}
